import 'package:flutter/material.dart';
import 'package:flutter_app_05/action/states/dark_states.dart';
import 'package:flutter_app_05/page/pagecal.dart';
import 'package:flutter_app_05/utils/MyTheme.dart';
import 'package:flutter_app_05/utils/ScreenAdapter.dart';
import 'package:flutter_app_05/widget/sdk_extends.dart';
import 'package:flutter_app_05/widget/stateful_widget_extends.dart';
import 'package:provider/provider.dart';

import 'calpage/page09.dart';
import 'calpage/pagecal01.dart';
import 'calpage/pagecal03.dart';
import 'calpage/pagecal04.dart';
import 'calpage/pagecal05.dart';
import 'calpage/pagecal07.dart';
import 'calpage/pagecal08.dart';

//首页
class IndexPage extends StatefulWidget {
  @override
  IndexPagePageState createState() => new IndexPagePageState();
}

class IndexPagePageState extends State<IndexPage> {
  DartState _categoryState;
@override
  void initState() {
    // TODO: implement initState
    super.initState();

  }
  @override
  Widget build(BuildContext context) {
    ScreenAdapter.init(context);
    Widget hcon = Container(
      width: ScreenAdapter.width(30.0),
    );
    Widget wcon = Container(
      height: ScreenAdapter.height(30.0),
    );
    return Consumer<DartState>(builder: (context, categoryState, child) {
      categoryState.initMode();
      this._categoryState = categoryState;
      return Container(
        color: MyTheme(context).getColor('bg'),
        child: Column(
          children: [
            Container(
              height: ScreenAdapter.height(155.0),
              alignment: Alignment.center,
              padding: EdgeInsets.only(top: 40),
              color: _categoryState.darkMode == 1
                  ? MyTheme.colorLight['app_green']
                  : MyTheme.colorDark['dark_app_green'],
              child: Image(
                image: AssetImage("images/icon_mini.png"),
                height: 30,
              ),
            ),
            SingleChildScrollView(
              child: Center(
                  child: SingleChildScrollView(
                child: Column(
                  mainAxisAlignment: MainAxisAlignment.spaceBetween,
                  children: [
                    wcon,
                    Row(
                      mainAxisAlignment: MainAxisAlignment.spaceAround,
                      children: [
                        buildButton("管控",
                            img: "images/icon_home_0.png", initIndex: 0),
                        buildButton("阻力",
                            img: "images/icon_home_1.png", initIndex: 1),
                      ],
                    ),
                    wcon,
                    Row(
                      mainAxisAlignment: MainAxisAlignment.spaceAround,
                      children: [
                        buildButton("膨胀",
                            img: "images/icon_home_2.png", initIndex: 2),
                        buildButton("水泵",
                            img: "images/icon_home_3.png", initIndex: 3),
                      ],
                    ),
                    wcon,
                    Row(
                      mainAxisAlignment: MainAxisAlignment.spaceAround,
                      children: [
                        buildButton("换热器", img: "images/icon_home_4.png"),
                        buildLastButton(),
                      ],
                    ),
                    wcon,
                    wcon,
                  ],
                ),
              )),
            )
          ],
        ),
      );
    });
//    return
  }

  Widget buildButton(String text, {String img, int initIndex = 0}) {
    Widget box = Container(
      width: 15.0,
      height: 3.0,
      color: Colors.grey,
    );
    Widget devide = SizedBox(
      height: 10.0,
    );
    return GestureDetector(
      child: Container(
        width: 160.0,
        height: 160.0,
        decoration: BoxDecoration(
          color: _categoryState.darkMode == 1
              ? MyTheme.colorLight['white']
              : MyTheme.colorDark['dark_app_green'],
          border: Border.all(
            color: Colors.transparent,
            width: 2,
          ),
          borderRadius: BorderRadius.circular(12),
        ),
        child: Center(
          child: Column(
            children: [
              devide,
              box,
              devide,
              img == null
                  ? "https://avatar-static.segmentfault.com/229/294/229294182-5d46e5a4cf510_huge256"
                      .getImage(
                      width: ScreenAdapter.width(110.0),
                      height: ScreenAdapter.height(80.0),
                    )
                  : Image(
                      image: AssetImage(img),
                      width: 100,
                      height: 100,
                    ),
              // img.getImage(width: 40,
              //   height:40,),
              devide,
              Text(
                text,
                style: TextStyle(
                    color: _categoryState.darkMode == 1
                        ? MyTheme.colorLight['colorBlack']
                        : MyTheme.colorDark['dark_colorBlack']),
              )
            ],
          ),
        ),
      ),
      onTap: () {
        this.push(FirstPage(
          pagenum: initIndex,
        ));
      },
    );
  }

  Widget buildLastButton() {
    return Container(
      width: 170.0,
      height: 170.0,
      child: InkWell(
        child: Stack(
          alignment: Alignment.center,
          children: [
            Image.asset("images/icon_bottom_green.png"),
            Positioned(
                child: Container(
              margin: EdgeInsets.all(25),
              child: Image.asset("images/icon_logo.png"),
            )),
          ],
        ),
        onTap: () {
          this.push(Padecalnine());
        },
      ),
    );
  }
}
